﻿using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using BusinessLayer;

namespace HorizonWS
{
    /// <summary>
    /// Provides all the functionalities to the ASP.NET application.
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [ToolboxItem(false)]
    public class Service : System.Web.Services.WebService
    {
        [WebMethod]
        public int GetWaitListCount(string flightNo)
        {
            int waitListCount = 0;

            try
            {
                using (BL bLayer = new BL())
                {
                    waitListCount = bLayer.GetWaitListCount(flightNo);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return waitListCount;
        }

        [WebMethod]
        public bool Reserve(int pnr, string flightNo, string fName, string lName, int age, char gender, char seatClass, string seatPref, string mealPref, string ssr, DateTime date)
        {
            try
            {
                using (BL bLayer = new BL())
                {
                    return bLayer.Reserve(pnr, flightNo, fName, lName, age, gender, seatClass, seatPref, mealPref, ssr, date);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
     
        [WebMethod]
        public DataTable GetFlights(DateTime date, string sector)
        {
            DataTable dt = new DataTable();

            try
            {
                using (BL bLayer = new BL())
                {
                    dt = bLayer.GetFlights(date, sector);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return dt;
        }

        [WebMethod]
        public DataTable GetFlightsBySector(string sector)
        {
            DataTable dt = new DataTable();

            try
            {
                using (BL bLayer = new BL())
                {
                    dt = bLayer.GetFlights(sector);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return dt;
        }

        [WebMethod]
        public bool AddWaitList(int pnr, string flightNo, string fName, string lName, int age, char gender, char seatClass, string seatPref, string mealPref, string ssr)
        {
            try
            {
                using (BL bLayer = new BL())
                {
                    return bLayer.AddWaitList(pnr, flightNo, fName, lName, age, gender, seatClass, seatPref, mealPref, ssr);
                }

            }
            catch (Exception ex)
            {
                
                throw ex;
            }
        }
    }
}
